package com.qf.mybatisplus.rabbitMQ;

import com.qf.mybatisplus.service.SmsService;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;


//@Component
public class SmsConsumer {

    @Autowired
    private SmsService smsService;

    @RabbitListener(queuesToDeclare = @Queue(name = "phoneQueue"))
    public void consumerMessage(String msg, Channel channel, Message message) throws IOException {

        System.err.println("手机号码是："+msg);

        // 调用service发送短信验证
        Boolean phoneCode = smsService.getPhoneCode(msg);

        System.err.println("消息已消费"+phoneCode);

        channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
    }

}
